<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/9
 * Time: 9:12
 */

namespace common\business\mdm;


use common\consts\MdmConsts;
use common\models\Department;
use common\result\ActionResult;
use yii\helpers\Json;

class MdmService
{



    /**
     * @param $department Department
     *
     * @return ActionResult
     */
    public function createOrUpdateDepartment($department){
        $client = new \SoapClient('http://10.0.1.14/uapws/service/mdmRceive?wsdl');

        $paramsArr = [
            MdmConsts::INTER_CODE => MdmConsts::INT_CODE_DEPT,
            MdmConsts::DEPARTMENT_CODE => $department->number,
            MdmConsts::DEPARTMENT_NAME => $department->name,
            MdmConsts::S_S_ORG => $department->mdm_id,
        ];

        $paramsArr[MdmConsts::S_S_ORG] = '1001AA10000000002BM9';

        $paramsStr = Json::encode($paramsArr);
        $result = $client->mdmRceive([
            'sjson' => $paramsStr,
        ]);

        $resultArr = Json::decode($result);
        $isSuccess = $resultArr[MdmConsts::RESULT] == '1';
        $message = $resultArr[MdmConsts::MESSAGE];

        return new ActionResult($isSuccess, $message);
    }
}